﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace CopyFile
{
    class Program
    {
        static void Main(string[] args)
        {
            string folder = AppDomain.CurrentDomain.BaseDirectory;
            DirectoryInfo directory = new DirectoryInfo(folder);
            List<FileInfo> fileList = new List<FileInfo>();
            DateTime time = new DateTime();
            foreach (var item in directory.GetFiles("*.dat"))
            {
                fileList.Add(new FileInfo(item.FullName));
            }
            FileInfo file = null;
            foreach (var item in fileList)
            {
                if (item.LastWriteTime > time && item.Name != "save.dat")
                {
                    file = item;
                    time = item.LastWriteTime;
                }
                //Console.WriteLine(item.Name + ";" + item.LastWriteTime);
            }
            if (file == null)
            {
                return;
            }
            string tragetFile = folder + "save.dat";
            File.Delete(tragetFile);
            File.Copy(file.FullName, tragetFile);
            //Console.ReadKey();
        }
    }
}
